#include <SDL.h>
#include <iostream>
#include "res_path.h"
#include "cleanup.h"
#include "logger.h"
#include "renderer.h"

int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 320;

int main(int argc, char **argv){
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
		std::cout << "SDLInit Error: " << SDL_GetError() << std::endl;
		return 1;
	}

	SDL_Window *win = SDL_CreateWindow("Hello World!", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
	if (win == nullptr){
		logSDLError(std::cout, "SDL_CreateWindow Error");
		SDL_Quit();
		return 1;
	}

	SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (ren == nullptr){
		SDL_DestroyWindow(win);
		logSDLError(std::cout, "SDL_CreateRenderer Error");
		SDL_Quit();
		return 1;
	}

	SDL_Texture *tex = loadTexture(getResourcePath("Images") + "test.bmp", ren);
	if (tex == nullptr) {
		cleanup(tex, win);
		logSDLError(std::cout, "loadTexture Error");
		SDL_Quit();
		return 1;
	}

	// Render Process
	SDL_RenderClear(ren);

	renderTexture(tex, ren, 0, 0);

	SDL_RenderPresent(ren);
	
	SDL_Delay(2000);

	
	cleanup(tex, ren, win);
	SDL_Quit();

	SDL_Quit();

	return 0;
}